<template>
  <div>
    <el-row type="flex" class="row-bg" :active="active" finish-status="success">
      <el-col :span="14" :offset="6">
        <el-steps :active="active" simple align-center>
          <el-step
            title="新建客户"
            icon="el-icon-circle-plus-outline"
          ></el-step>
          <el-step title="查询客户" icon="el-icon-position"></el-step>

          <el-step title="新增成功" icon="el-icon-success"></el-step>
        </el-steps>
      </el-col>
    </el-row>
    <div v-show="active === 1">
      <el-row>
        <el-col :span="14" :offset="5">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="客户名称:" prop="partyName">
              <el-input v-model="ruleForm.partyName"></el-input>
            </el-form-item>
            <el-form-item label="证件类型:" prop="certType">
              <el-select
                v-model="ruleForm.certType"
                placeholder="请选择证件类型"
                @change="addcertTypeChange"
              >
                <el-option
                  v-for="item in selectInfo[0].val"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="证件号码:"
              prop="certNum"
              placeholder="请输入内容"
              :required="
                ruleForm.certType == '7' || ruleForm.certType == '72'
                  ? false
                  : true
              "
            >
              <el-input v-model="ruleForm.certNum"></el-input>
            </el-form-item>
            <el-form-item
              label="审核人:"
              :prop="shr_props ? 'auditName' : ''"
              :required="isAuditIdShow"
              v-show="isAuditIdShow"
            >
              <dic-customer-select
                :value="ruleForm.auditName"
                title="审核人"
                ref="auditIdRef"
                size="50%"
                @inLoadAjax="auditIdAjaxHandel"
              >
                <!-- 表单 -->
                <el-form
                  :inline="false"
                  label-width="100px"
                  :model="addauditIdForm"
                  ref="auditIdFormRef"
                >
                  <el-row :gutter="10">
                    <el-col :span="10">
                      <div class="grid-content bg-purple">
                        <el-form-item label="员工编码" class="u-ipt">
                          <el-input
                            placeholder=""
                            v-model="addauditIdForm.staffCode"
                            class="input-with-select"
                          >
                          </el-input>
                        </el-form-item>
                      </div>
                    </el-col>
                    <el-col :span="10">
                      <div class="grid-content bg-purple">
                        <el-form-item label="员工姓名" class="u-ipt">
                          <el-input
                            placeholder="请输入内容"
                            v-model="addauditIdForm.staffName"
                            class="input-with-select"
                          >
                          </el-input>
                        </el-form-item>
                      </div>
                    </el-col>
                    <el-col :span="4">
                      <el-button
                        type="primary"
                        size="small"
                        @click="auditIdQuery"
                        >查询</el-button
                      >
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="审核人姓名">
                        {{ addauditIdForm.staffNameChoose }}
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>

                <DicTable
                  ref="commonRegionTable"
                  stripe
                  highlight-current-row
                  :columnData="auditIdColumns"
                  :tableData="auditIdTableData"
                  :loading="auditIdTableLoading"
                  :currentPage="auditIdTablePage.pageIndex"
                  :pageSize="auditIdTablePage.pageSize"
                  :totalResult="auditIdTablePage.rowCount"
                  :pager="true"
                  @current-change="auditIdCurrentChangeEvent"
                  @on-page-change="auditIdHandlePageChange"
                >
                </DicTable>
                <div class="text-c">
                  <el-button
                    type="primary"
                    size="small"
                    @click="sunmitAuditIdHandel"
                    >确定</el-button
                  >
                </div>
              </dic-customer-select>
            </el-form-item>
            <el-form-item label="营销责任地:" prop="regionName">
              <el-input v-model="ruleForm.regionName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="证件照片:"
              :required="
                ruleForm.certType == '7' || ruleForm.certType == '72'
                  ? true
                  : false
              "
            >
              <el-upload
                :action="uploadUrl"
                list-type="picture-card"
                :show-file-list="true"
                :file-list="custAddList"
                :data="custAddData"
                :multiple="false"
                accept=".jpg,.jpeg,.png,.JPG,.JPEG"
                :on-change="custAddChange"
                :on-preview="custAddPreview"
                :on-success="custAddSuccess"
                :before-upload="custAddUpload"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="custAddDialogVisible" append-to-body>
                <img width="100%" :src="custAddDialogImageUrl" alt="" />
              </el-dialog>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <el-row style="text-align: center">
        <el-button type="primary" @click="nextStepHandel">下一步</el-button>
        <el-button @click="returnPreStep()">返回</el-button>
      </el-row>
    </div>
    <div v-show="active === 2">
      <DicTable
        ref="customertable"
        stripe
        max-height="400"
        :columnData="tableColumns"
        :tableData="tableData"
        :loading="tableLoading"
        :currentPage="tablePage.pageIndex"
        :pageSize="tablePage.pageSize"
        :totalResult="tablePage.totalResult"
        :pager="true"
        @on-page-change="handlePageChange"
        @radio-change="radioChangeHandel"
      >
        <template #detail="{ row }">
          <el-button type="text" @click="showManager(row)">客户经理</el-button
          >&nbsp;&nbsp;
          <el-button type="text" @click="showContact(row)">联系人</el-button>
        </template>
      </DicTable>
      <div style="text-align: center; margin-top: 10px">
        <el-button type="primary" @click="selectCustomer">确定</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </div>
      <dic-dialog
        :visible.sync="dialogVisible"
        width="45%"
        center
        append-to-body
      >
        <span>
          <DicTable
            ref="dicTable"
            stripe
            :columnData="viewTableColumns"
            :tableData="viewTableData"
          >
          </DicTable>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">关闭</el-button>
        </span>
      </dic-dialog>
      <dic-dialog
        :visible.sync="concatDialogVisible"
        width="45%"
        center
        append-to-body
      >
        <span>
          <el-form>
            <el-form-item label="客户名称:" prop="partyName">
              <el-input v-model="ruleForm.partyName"></el-input>
            </el-form-item>
            <el-form-item label="证件类型:" prop="certType">
              <el-select
                v-model="ruleForm.certType"
                placeholder="请选择证件类型"
                @change="certTypeChange"
              >
                <el-option
                  v-for="item in selectInfo[0].val"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="证件号码:"
              prop="certNum"
              placeholder="请输入内容"
              :required="ruleForm.certType == '7'"
            >
              <el-input v-model="ruleForm.certNum"></el-input>
            </el-form-item>
          </el-form>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">关闭</el-button>
        </span>
      </dic-dialog>
    </div>
    <div v-show="active >= 3">新增成功</div>
    <el-dialog
      title="合规性认证"
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="isShow"
      v-if="isShow"
      :isShow.sync="isShow"
      width="40%"
    >
      <component
        v-bind:is="whichComp"
        :data="changeNameForm"
        @subitForm="subitForm"
        @cancelHandel="cancelHandel"
      ></component>
    </el-dialog>
    <!-- 省客户列表 -->
    <dic-customer-btn-drawer
      title="省客户列表"
      ref=""
      size="70%"
      btnShow="true"
      :isShow.sync="proIsShow"
      @closeDrawer="submitConcatFormNotComplete"
      @cancelForm="proIsShow = false"
    >
      <el-form
        :model="contactRuleForm"
        :rules="singleContactRule"
        ref="singleContactRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="联系人名称:" prop="contactName">
              <el-input v-model="contactRuleForm.contactName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="移动电话:" prop="mobilePhone" required>
              <el-input v-model="contactRuleForm.mobilePhone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="Email:" prop="contactEmail">
              <el-input v-model="contactRuleForm.eMail"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row> </el-row>
      </el-form>
    </dic-customer-btn-drawer>
    <dic-dialog
      title="提示"
      :visible.sync="onComplianceVisible"
      width="70%"
      :close-on-click-modal="false"
      append-to-body
    >
      <span>
        <el-alert
          :title="alertTitle"
          type="warning"
          :closable="false"
          class="mb20"
        >
        </el-alert>

        <DicTable
          v-show="DicTableIsShow"
          stripe
          :columnData="nonComplianceviewTableColumns"
          :tableData="nonComplianceviewTableData"
        >
          <template #opt="{ row }">
            <el-button type="primary" @click="changeRow(row)">选择</el-button>
          </template>
        </DicTable>
        <el-alert
          v-if="titleMsgIsshow"
          :title="titleMsg"
          type="warning"
          :closable="false"
          class="mt20"
        >
        </el-alert>
      </span>

      <span slot="footer" class="dialog-footer">
        <el-button @click="onComplianceVisible = false">关闭</el-button>
      </span>
    </dic-dialog>
  </div>
</template>

<script>
import Vue from "vue";
import DicTable from "@/components/public/DicTable";
import DicDialog from "@/components/dicppm-ui/DicDialog";
import DicCustomerSelect from "@/components/customer/form/DicCustomerSelect";
import DicCustomerBtnDrawer from "@/components/customer/form/DicCustomerBtnDrawer";
import CustomerInfoManageServer from "@/api/customer/CustomerInfoManageServer";
import Compliance from "@/views/customer/customer-dialog/Compliance";
import { mapState } from "vuex";
import validRules from "@/views/customer/valide/gaoyjValidRules.js";

Vue.use(DicTable);
export default {
  data() {
    return {
      labelPosition: "left",
      concatList: [],
      // 判断联系人信息是否完全
      concatFlag: false,
      // 用来判断证件类型是否是党政军，证件照片是必填的
      concatDialogVisible: false,
      onComplianceVisible: false,
      sessonPulicParams: {
        commonRegionId: "",
        regionType: "",
        orgId: "",
        staffId: "",
      },
      // 审核人是否显示
      isAuditIdShow: false,
      // 判断审核人是否有值
      isAuditIdFlag: 0,
      // 证件号码是否是必填项

      dialogVisible: false,
      active: 1,

      // 原来的select 数组
      imageUrl: "",
      // 境外客户查看权限
      rolesCount: "",
      //
      ruleForm: {
        partyName: "", //客户名称
        certType: "", //证件类型
        certNum: "", //证件号码
        regionName: "", //营销责任地名称
        regionNbr: "", //营销责任地编码
        auditId: "", //审核人id
        audit: "",
        auditName: "", //审核人名称
        photoName: "", //证件名称
        photoPath: "", //证件路径
        staffId: "",
        commonRegionId: "",
        certAddr: "", //查询省客户返回地址
      },
      rules: {
        partyName: [
          { required: true, message: "请输入客户名称!", trigger: "blur" },
        ],

        certType: [
          {
            required: true,
            validator: validRules.gaoyj_checkIdCardSType,
            message: "请选择证件类型",
            trigger: "change",
          },
        ],

        certNum: [
          {
            validator: validRules.gaoyj_checkIdCardNum,
            trigger: "blur",
          },
        ],
        auditName: [
          { validator: validRules.gaoyj_checkAuditName, trigger: "blur" },
        ],
        regionName: [
          { required: true, message: "请填写营销责任地", trigger: "blur" },
        ],
        // custAddData:[
        //    {  validator: validRules.gaoyj_checkedPhotoPath, trigger: "change" },
        // ]
      },
      tableColumns: [
        { type: "radio", title: "选择", width: 80, fixed: null },
        { field: "orgUscc", title: "统一社会信用代码" },
        { field: "custName", title: "客户名称", showOverflow: true },
        { field: "commonRegionName", title: "归属区域" },
        { field: "custId", title: "省客户ID" },
        {
          field: "custNumber",
          title: "省客户编码",
          showOverflow: true,
        },
        { field: "registerAddr", title: "客户地址", showOverflow: true },
        { slotName: "detail", title: "详情" },
      ],
      tableData: [],
      tableLoading: false,
      tablePage: {
        pageIndex: 1,
        pageSize: 10,
        totalResult: 0,
      },
      viewTableColumns: [],
      viewTableData: [],
      isShow: false,
      // 省客户列表弹窗显示隐藏
      proIsShow: false,
      // 联系人-表单
      contactRuleForm: {
        contFlag: "false",
        // 联系人名称
        contactName: "",
        // 联系人-移动电话
        mobilePhone: "",
        // 联系人-email
        eMail: "",
      },
      // 联系人信息不全的
      singleContactRule: {
        contactName: [
          { required: true, message: "请输入客户名称", trigger: "blur" },
        ],
        mobilePhone: [
          { validator: validRules.gaoyj_checkeMmobilePhone, trigger: "blur" },
        ],
      },
      // 公共参数
      publicParams: {
        custId: "",
      },
      nonComplianceviewTableColumns: [
        { field: "jtCustName", title: "客户名称" },
        {
          field: "orgUscc",
          title: "统一社会信用代码",
          width: 200,
          showOverflow: true,
        },
        { field: "certNum", title: "组织机构代码" },
        { field: "registerAddr", title: "注册地址", width: 400 },
        { slotName: "opt", title: "操作" },
      ],
      // 合规性不通过的逻辑列表
      nonComplianceviewTableData: [],

      addauditIdForm: {
        staffCode: "", //审核人编码
        staffName: "", //审核人名称
        staffNameChoose: "",
        staffCodeId: "", //选择审核人编码存放变量
      },
      auditIdColumns: [
        {
          field: "STAFF_CODE",
          title: "员工编码",
          fixed: "left",
          showOverflow: true,
          width: 100,
        },
        {
          field: "STAFF_NAME",
          title: "员工姓名",
          width: 200,
          fixed: "left",
          showOverflow: true,
        },
        { field: "MOBILE_PHONE", title: "员工联系方式", width: 200 },
        { field: "ORG_NAME", title: "组织名称", width: 200 },
        { field: "DEPARTMENT_NAME", title: "部门名称", width: 200 },
      ],
      auditIdTableData: [],
      auditIdTableLoading: false,
      auditIdTablePage: {
        pageIndex: 1,
        pageSize: 5,
        rowCount: 0,
        pageCount: 0,
      },

      //单条数据的时候返回的json
      returnjson: {},
      // 多条的时候判断的条件
      moreFlag: false, //代表多条
      // 点击地下确定的时候去判断联系人信息是否完整 变量
      moreJson: {},
      // 下拉框的取值
      selectInfo: [
        {
          flag: "cert_type", //改名改证件
          val: [],
        },
      ],
      //新建客户-上传证件照片
      uploadUrl: `${process.env.VUE_APP_CTX_CUST}/saveCustFile`,
      //  新建客户-上传证件照片下后台传递的数据
      custAddData: {
        fileFlag: "partyNew",
        oldPhotoPath: "",
      },
      //  新建客户证件照片列表
      custAddList: [],
      custAddDialogVisible: false,
      custAddDialogImageUrl: "",
      //  合规性认证标题与提示
      alertTitle: "",
      titleMsg: "",
      DicTableIsShow: false,
      titleMsgIsshow: false,
      whichComp: Compliance,
      //  合规性认证向自组建传递的数据
      changeNameForm: {
        flag: "new",
        custId: "",
        partyId: "",
        statusCd: "", //进入改名改证件 用来判断 审核人是否显示的字段
      },
      R_Count:'',//当为0是直接跳填报页面
      shr_props:false,//审核人必填校验
    };
  },
  components: {
    DicTable,
    DicDialog,
    DicCustomerSelect,
    DicCustomerBtnDrawer,
    Compliance,
  },
  created() {
    // 
  },
  mounted() {
    this.$nextTick(() => {
      this.initParty();
      this.initValue();
      this.$refs["ruleForm"].resetFields();
    });
  },
  computed: {
    ...mapState("user", ["user"]),
  },
  methods: {
    custAddSuccess(res, file) {
      var _this = this;
      
      this.ruleForm.photoName = file.name;
      this.ruleForm.photoPath = res.meta.photoPath;
      this.custAddData.oldPhotoPath = res.meta.photoPath;
      if (res.code == 200) {
        this.$notify({
          title: "成功",
          message: "图片上传成功",
          type: "success",
        });
        this.$refs.ruleForm.clearValidate("photoName");
      }
    },
    custAddUpload(file) {
      const isPicType =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/jpg" ||
        file.type === "image/JPG" ||
        file.type === "image/JPEG";
      const isLt10M = file.size / 1024 / 1024 < 10;
      if (!isPicType) {
        this.$message.error("上传头像图片只能是 JPG或者Png 格式!");
      }
      if (!isLt10M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isPicType && isLt10M;
    },
    custAddPreview(file) {
      this.custAddDialogImageUrl = file.url;
      this.custAddDialogVisible = true;
    },
    custAddChange(file, fileList) {
      var returnArr;
      if (fileList.length > 1) {
        returnArr == fileList.shift();
      }
      this.custAddList = fileList;
    },
    /*
    新建客户初始化服务
    time：20210416
    */
    async initParty() {
      var params = {
        commonRegionId: this.user.regionId,
        regionType: this.user.regionType,
        orgId: this.user.orgId,
        staffId: this.user.staffId,
      };
      let res = await CustomerInfoManageServer.initParty(params);
      if (res.code == 200) {
        
        this.ruleForm.commonRegionId = res.meta.commonRegionId;
        this.ruleForm.regionName = res.meta.regionName;
        this.ruleForm.regionNbr = res.meta.regionNbr;
        this.rolesCount = res.meta.rolesCount;
        this.R_Count = res.meta.R_Count;
        if (this.rolesCount == 0) {
          for (var i = 0; i < this.selectInfo[0].val.length; i++) {
            if (this.selectInfo[0].val === "72") {
              this.selectInfo.splice(i, 1);
            }
          }
        }
      }
    },
    //证件类型切换
    addcertTypeChange(val) {
      this.$refs.ruleForm.clearValidate();
      //  this.$refs.ruleForm.clearValidate('certNum');
      //  this.$refs.ruleForm.clearValidate('photoPath');
      //  this.$refs.ruleForm.clearValidate('photoName');
      let org = "";
      if ((val == "7" || val == '72') && this.user.orgId != "1944640") {
        this.isAuditIdShow = true;
        this.shr_props = true;
      } else {
        this.shr_props = false;
        this.isAuditIdShow = false;
        this.ruleForm.auditName = "";
        this.ruleForm.auditId = "";
      }
    },
    // 证件类型
    certTypeChange(val) {
      
      this.ruleForm.certNum = "";
      let org = "";
      if (val == "7" && this.user.orgId != "1944640") {
        this.isAuditIdShow = true;
      } else {
        this.isAuditIdShow = false;
      }
    },
    //  新建客户点击下一步ajax交互
    nextStepHandel() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.nextStep();
        } else {
          return false;
        }
      });
    },

    async nextStep() {
      if (this.ruleForm.photoPath == "" && this.isAuditIdShow) {
        this.$alert("证件照片:不能为空!", "提示", { type: "warning" });
        return;
      }
      let loadingInstance = this.$loading({ fullscreen: true });
      var params = {
        partyName: this.ruleForm.partyName,
        certType: this.ruleForm.certType,
        certNum: this.ruleForm.certNum,
        staffId: this.user.staffId,
        staffName: this.user.staffName,
        photoName: this.ruleForm.photoName,
        photoPath: this.ruleForm.photoPath,
        auditor:this.addauditIdForm.staffCodeId
      };
      let result = await CustomerInfoManageServer.setNewCustomer(params);
      var res = result.meta;
      if (result.code == 200) {
        // 当identityType=="1" || identityType=="2" 说明客户已经合规，提供查看证件详情查看页面
        // result.meta.identityType = 3;
        if (res.step == "1") {
          loadingInstance.close();
          if (
            result.meta.identityType == "1" ||
            result.meta.identityType == "2"
          ) {
            // 消息提示框
            this.$confirm("该用户已存在,请直接进行业务受理?", "提示", {
              confirmButtonText: "查看客户视图",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                this.$router.push({
                  path: "/custView",
                  query: {
                    partyId: res.partyId,
                    staffId: this.user.staffId,
                    type: "customerAdd",
                    custId: result.meta.custId,
                  },
                });
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "",
                });
              });
            //客户视图
          } else if (
            result.meta.identityType != "1" &&
            result.meta.identityType != "2"
          ) {
            // 当identityType！="1" && identityType！="2" 说明客户未合规，提供客户合规页面
            //改名改证件
            this.$confirm(
              "请注意当前营销责任地下客户已存在单资料未合规?请进行合规性验证",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              }
            )
              .then(() => {
                this.changeNameForm.partyId = result.meta.partyId;
                this.changeNameForm.custId = result.meta.custId;
                this.isShow = true;
                // 初始化合规性认证接口
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "",
                });
              });
          }
        } else if (res.step == "2") {
          loadingInstance.close();
          if (res.ruleCode == "-1") {
            this.$confirm(res.ruleMsg, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }).then(() => {
              this.ceratyParty(params);
            });
          } else {
            this.onComplianceVisible = true;
            if (res.ruleCode == "10002") {
              this.alertTitle =
                "合规性验证不通过：组代无数据，请确认是否以下疑似客户:";
              this.titleMsg = "如非以上疑似客户请上传证件照片";
              this.titleMsgIsshow = true;
              this.DicTableIsShow = true;
            } else if (
              res.ruleCode == "10003" ||
              res.ruleCode == "10004" ||
              res.ruleCode == "10005"
            ) {
              this.alertTitle =
                "合规性验证不通过：客户名称不一致，正确客户信息如下：";
              (this.titleMsg = ""), (this.titleMsgIsshow = false);
              this.DicTableIsShow = true;
            } else if (res.ruleCode == "10010" || res.ruleCode == "10011") {
              this.alertTitle =
                "合规性验证不通过：证件号码不一致，正确客户信息如下：";
              (this.titleMsg = ""), (this.titleMsgIsshow = false);
              this.DicTableIsShow = true;
            } else {
              this.alertTitle = res.ruleMsg;
              (this.titleMsg = ""), (this.titleMsgIsshow = false);
              this.DicTableIsShow = true;
            }
            this.nonComplianceviewTableData = result.meta.suspectedCust;
          }
        } else if (res.step == "3") {
          // res.step=3 代表新建完成
          this.ruleForm.certAddr = res.certAddr;
          this.ruleForm.partyId = res.partyId;
          this.ruleForm.partyNbr = res.partyNbr;
          if(this.R_Count == 0) {
            loadingInstance.close();
            this.$router.push({
              path: "/custProvided",
              query: {
                partyId: this.ruleForm.partyId,
                staffId: this.user.staffId,
                type: "customerAdd",
                custflag: this.ruleForm.auditId,
                partyNbr: this.ruleForm.partyNbr,
                commonRegionId: this.ruleForm.commonRegionId,
                regionName: this.ruleForm.regionName,
              },
            });
          }else {
            //查询省客户接口
            this.getProvinceCustList(
              result.meta.partyNbr,
              this.ruleForm.regionNbr
            );
          }
        }
      }else {
        this.$notify.error({
          title: "错误",
          message: result.msg,
        });
      }
    },

    // 下拉框初始化
    async initValue(flag) {
      let response = "";
      this.selectInfo.forEach(async (item, index) => {
        response = await CustomerInfoManageServer.initValue({
          flag: item.flag,
        });
        if (response.code == 200) {
          this.selectInfo[index].val = response.meta.customers;
        }
      });
      
    },

    // 省客户返回多条时 -点击单选按钮
    radioChangeHandel({ row }) {
      
      this.concatList = row.contacts;
      this.returnjson = row;
      
    },

    // 点击执行保存的方法

    async saveRadioChangeSubmit(
      contFlag,
      contactName,
      mobilePhone,
      eMail,
      returnjson
    ) {
      let params = {
        staffId: this.user.staffId,
        contFlag: contFlag,
        commonRegionId: this.user.regionId,
        partyId: this.ruleForm.partyId,
        certAddr: this.ruleForm.certAddr,
        certType: this.ruleForm.certType,
        audit: this.ruleForm.audit,
        CONTACT_NAME: contactName,
        MOBILE_PHONE: mobilePhone,
        E_MAIL: eMail,
        returnjson: encodeURI(JSON.stringify(returnjson), "utf-8"),
      };
      let result = await CustomerInfoManageServer.saveProvCust(params);
      this.$confirm("信息保存成功", "提示", {
        confirmButtonText: "确定",
        type: "success",
        center: true,
        showCancelButton: false,
      })
        .then(() => {
          this.active = 3;
          this.$router.push({
            path: "/custbaseinf",
          });
        })
        .catch(() => {});
    },

    // 新建客户查询省客户服务
    async getProvinceCustList(partyNbr, regionNbr) {
      let loadingInstance = this.$loading({ fullscreen: true });
      var params;
      if ("91510104MA6CTA573X" == this.ruleForm.certNum) {
        params = {
          partyName: this.ruleForm.partyName,
          regionNbr: regionNbr,
          partyNbr: partyNbr,
          certNum: "0",
          pageIndex: this.tablePage.pageIndex,
          pageSize: this.tablePage.pageSize,
        };
      } else {
        params = {
          partyName: this.ruleForm.partyName,
          regionNbr: regionNbr,
          partyNbr: partyNbr,
          certNum: this.ruleForm.certNum,
          pageIndex: this.tablePage.pageIndex,
          pageSize: this.tablePage.pageSize,
        };
      }
      let result = await CustomerInfoManageServer.getProvinceCust(params);
      loadingInstance.close()
      if (result.code == 200) {
        if (result.meta.total == "0") {
          this.$router.push({
            path: "/custProvided",
            query: {
              partyId: this.ruleForm.partyId,
              staffId: this.user.staffId,
              type: "customerAdd",
              custflag: this.ruleForm.auditId,
              partyNbr: this.ruleForm.partyNbr,
              commonRegionId: this.ruleForm.commonRegionId,
              regionName: this.ruleForm.regionName,
            },
          });
        } else if (result.meta.total == "1") {
          //  result.meta.contFlag="false";
          if (result.meta.contFlag == "true") {
            //调用保存功能
            this.contactRuleForm.contFlag = result.meta.contFlag;
            this.returnjson = result.meta.customer[0];

            //  为true的时候说明客户信息完整 不用穿后台联系人信息
            this.saveRadioChangeSubmit(
              result.meta.contFlag,
              "",
              "",
              "",
              this.returnjson
            );
          } else {
            
            (this.returnjson = result.meta.customer[0]),
              (this.proIsShow = true);
            // 调用保存功能
          }
        } else {
          
          this.active = 2;
          
          this.tableData = result.meta.customer;
          this.tablePage.totalResult = Number(result.meta.total);
        }
      }
    },
    // 新建客户
    changeRow(row) {
      this.ruleForm.partyName = row.jtCustName;
      this.isAuditIdShow = false;
      this.ruleForm.auditName = "";
      this.ruleForm.auditId = "";
      if (row.orgUscc) {
        this.ruleForm.certNum = row.orgUscc;
        // 赋值证件类型
        this.ruleForm.certType = "49";
      } else {
        this.ruleForm.certNum = row.certNum;
        this.ruleForm.certType = "15";
      }

      this.onComplianceVisible = false;
    },
    /* 遵循现网逻辑，接口异常，页面展示出选择框，
      提示，“合规性验证异常，暂时无法获取身份证信息，可继续进行业务受理!”，
      点击确认后进行证件新增*/
    async ceratyParty(params) {
      let result = await CustomerInfoManageServer.ceratyParty(params);
      var res = result.meta;
      if (result.code == 200) {
        // 当identityType=="1" || identityType=="2" 说明客户已经合规，提供查看证件详情查看页面
        // result.meta.identityType = 3;

        if (res.step == "1") {
          if (res.identityType == "1" || res.identityType == "2") {
            // 消息提示框
            this.$confirm("该用户已存在,请直接进行业务受理?", "提示", {
              confirmButtonText: "查看客户视图",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                this.$router.push({
                  path: "/custView",
                  query: {
                    partyId: this.ruleForm.partyId,
                    staffId: this.user.staffId,
                    type: "customerAdd",
                    custId: result.meta.custId,
                  },
                });
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "",
                });
              });
            //客户视图
          } else if (res.identityType != "1" && res.identityType != "2") {
            // 当identityType！="1" && identityType！="2" 说明客户未合规，提供客户合规页面
            //改名改证件
            this.$confirm(
              "请注意当前营销责任地下客户已存在单资料未合规?请进行合规性验证",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              }
            )
              .then(() => {
                // 这块目前先赋值 周有接口会修改
                this.changeNameForm.partyId = result.meta.partyId;
                this.changeNameForm.custId = result.meta.custId;
                this.isShow = true;
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "",
                });
              });
          }
        } else if (res.step == "3") {
          // res.step=3 代表新建完成
          this.ruleForm.certAddr = res.certAddr;
          this.ruleForm.partyId = res.partyId;
          this.ruleForm.partyNbr = res.partyNbr;

          //查询省客户接口
          this.getProvinceCustList(
            result.meta.partyNbr,
            this.ruleForm.regionNbr
          );
        }
      }
    },
    //新建客户-审核人点击方法
    auditIdAjaxHandel(row) {
      this.auditIdTablePage.pageIndex = 1;
      this.auditIdTablePage.pageSize = 5;
      this.auditIdAjax();
    },
    subitForm() {
      this.isShow = false;
      this.$router.push("/custbaseinf");
    },
    // 审核人的ajax-初始化
    async auditIdAjax() {
      let params = {
        staffId: this.user.staffId,
        pageIndex: this.auditIdTablePage.pageIndex,
        pageSize: this.auditIdTablePage.pageSize,
        staffCode: this.addauditIdForm.staffCode,
        staffName: this.addauditIdForm.staffName,
      };
      let res = await CustomerInfoManageServer.getAuditorList(params);
      if (res.code == 200) {
        this.auditIdTableData = res.meta.customers || [];
        this.auditIdTablePage.rowCount = Number(res.meta.pageInfo.rowCount);
        this.auditIdTablePage.pageCount = Number(res.meta.pageInfo.pageCount);
      } else {
        this.$notify.error({
          title: "错误",
          message: response.msg,
        });
      }
    },

    // 新建客户-证件类型切换党政军-显示的审核人弹窗-点击行
    auditIdCurrentChangeEvent(val) {
      
      
      this.addauditIdForm.staffNameChoose = val.data[val.$rowIndex].STAFF_NAME;
      this.addauditIdForm.staffCodeId = val.data[val.$rowIndex].STAFF_ID;
    },
    // 新建客户-证件类型切换党政军-显示的审核人弹窗-分页
    auditIdHandlePageChange(val) {
      this.auditIdTablePage.pageIndex = val.currentPage;
      this.auditIdTablePage.pageSize = val.pageSize;
      this.auditIdAjax();
    },

    // 返回客户列表首页
    returnPreStep() {
      this.$router.push("/custbaseinf");
    },
    resetForm(formName) {
      this.active = 1;
      // this.$nextTick(() => {
      //   this.$refs[formName].resetFields();
      // });
    },
    handlePageChange({ currentPage, pageSize }) {
      
      this.tablePage.pageIndex = currentPage;
      this.tablePage.pageSize = pageSize;
      //查询省客户接口
      this.getProvinceCustList(this.ruleForm.partyNbr, this.ruleForm.regionNbr);
    },
    // findList() {
    //   this.tableData = [
    //     {
    //       id: 10008,
    //       name: "Test11",
    //       nickname: "T11",
    //       role: "Develop",
    //       sex: "Man ",
    //       age: 35,
    //       address: "vxe-table 从入门到放弃11",
    //     },
    //   ];
    //   this.tablePage.totalResult = 1;
    // },

    // 点击确定
    selectCustomer() {
      var _this = this;
      var flag = false;
      if (_this.concatList.length > 0) {
        //   _this.concatList.forEach(function(element) {
        //   if(element.contactName!=""&& element.contactName!="undefind" &&element.contactName!= null && element.mobilePhone!=""&& element.mobilePhone!="undefind" && element.mobilePhone!=null && !flag){
        //     // 如果联系人信息全的情况 moreflag：true
        //       // 不全为false
        //     flag = true;
        //     _this.contactRuleForm.contFlag="true";
        //      _this.active = 3;
        //     _this.saveRadioChangeSubmit(_this.contactRuleForm.contFlag,"","","", _this.returnjson);
        //  }else{
        //     _this.contactRuleForm.contFlag=false;
        //     _this.proIsShow=true;
        //   }
        // });
        for (let i = 0; i < _this.concatList.length; i++) {
          if (
            _this.concatList[i].contactName != "" &&
            _this.concatList[i].contactName != "undefind" &&
            _this.concatList[i].contactName != null &&
            _this.concatList[i].mobilePhone != "" &&
            _this.concatList[i].mobilePhone != "undefind" &&
            _this.concatList[i].mobilePhone != null
          ) {
            _this.contactRuleForm.contFlag = "true";
            _this.active = 3;
            _this.saveRadioChangeSubmit(
              _this.contactRuleForm.contFlag,
              "",
              "",
              "",
              _this.returnjson
            );
            break;
          } else {
            _this.contactRuleForm.contFlag = false;
            _this.proIsShow = true;
          }
        }
      } else {
        this.contactRuleForm.contFlag = false;
        this.proIsShow = true;
      }
    },
    //客户经理展示
    showManager(row) {
      
      this.dialogVisible = true;
      this.viewTableColumns = [
        { field: "staffId", title: "客户经理账号", width: 200 },
        {
          field: "staffName",
          title: "客户经理名称",
          width: 200,
          showOverflow: true,
        },
        { field: "staffCode", title: "人力账号", width: 200 },
        { field: "mobilePhone", title: "电话", width: 200 },
      ];

      this.viewTableData = row.custManagerTeams;
    },
    //联系人信息展示
    showContact(row) {
      this.dialogVisible = true;
      this.viewTableColumns = [
        {
          field: "contactName",
          title: "联系人姓名",
          width: 200,
          showOverflow: true,
        },
        { field: "mobilePhone", title: "联系人电话", width: 200 },
        { field: "eMail", title: "邮箱", width: 200 },
      ];
      this.viewTableData = row.contacts;
    },
    // 审核人ajax
    ruleFormAjax() {},
    // 下一步 1条时如果联系人信息不全也会返回页面 提交表单
    contactSunmit() {},
    // 调省客户信息不完整返回一条时调用的接口信息不完整点击方法
    submitConcatFormNotComplete() {
      // 校验联系人信息-全不全
      this.$refs.singleContactRef.validate((valid) => {
        if (valid) {
          this.saveRadioChangeSubmit(
            this.contactRuleForm.contFlag,
            this.contactRuleForm.contactName,
            this.contactRuleForm.mobilePhone,
            this.contactRuleForm.eMail,
            this.returnjson
          );
        } else {
          return false;
        }
      });
    },

    //新建客户-合规性认证 取消
    cancelHandel() {
      this.isShow = false;
    },
    // 点击审核人弹窗-确定将审核人的id带过来
    sunmitAuditIdHandel() {
      this.ruleForm.auditId = this.addauditIdForm.staffCodeId;
      this.ruleForm.auditName = this.addauditIdForm.staffNameChoose;
      this.$refs.auditIdRef.drawer = false;
    },
    // 审核人查询方法
    auditIdQuery() {
      this.auditIdTablePage.pageIndex = 1;
      this.auditIdTablePage.pageSize = 5;
      this.auditIdAjax();
    },
  },
};
</script>
<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.mb20 {
  margin-bottom: 0.2rem;
}
.mt20 {
  margin-top: 0.2rem;
}
::v-deep .el-steps--simple {
  background-color: #fff;
}
::v-deep .el-step.is-simple .el-step__title {
  font-size: $fontSize_v3;
  font-weight: 400;
}
::v-deep .el-dialog__body {
  padding: 0.1rem 0.2rem 0.2rem 0.2rem !important;
}
::v-deep .el-step__title.is-process,
::v-deep .el-step__head.is-process,
::v-deep .el-step__title .is-wait {
  color: rgba(153, 153, 153, 0.5);
}
::v-deep .el-step__icon-inner.iconfont {
  font-size: 0.19rem;
}
::v-deep .el-step__head.is-wait {
  color: rgba(153, 153, 153, 0.5);
}
::v-deep .el-step.is-simple .el-step__head {
  padding-right: 0.04rem;
}
::v-deep .el-step.is-simple .el-step__arrow::before,
::v-deep .el-step.is-simple .el-step__arrow::after {
  content: "";
  display: inline-block;
  position: absolute;
  height: 0.01rem;
  width: 40%;
  background: rgba(153, 153, 153, 0.4);
  transform: none;
}
::v-deep .el-step.is-simple .el-step__arrow::before {
  display: none;
}
::v-deep .el-step.is-simple {
  cursor: pointer;
}
.row-bg {
  margin-bottom: 0.3rem;
}
.el-icon-plus {
  border: 1px dashed #d9d9d9;
}
.text-c {
  text-align: center;
}
</style>
